package com.netease.nim.demo.session.audio;

import com.netease.nim.demo.common.media.audioplayer.Playable;
import com.netease.nimlib.sdk.msg.attachment.AudioAttachment;
import com.netease.nimlib.sdk.msg.model.IMMessage;

public class MsgHistoryPlayableWrapper implements Playable {

	private IMMessage playableMessageHistory;

	public IMMessage getPlayableMessageHistory() {
		return playableMessageHistory;
	}

	public MsgHistoryPlayableWrapper(IMMessage playableMessage) {
		this.playableMessageHistory = playableMessage;
	}

	@Override
	public long getDuration() {
		return ((AudioAttachment) playableMessageHistory.getAttachment()).getDuration();
	}

	@Override
	public String getPath() {
		return ((AudioAttachment) playableMessageHistory.getAttachment()).getPath();
	}

	@Override
	public boolean isAudioEqual(Playable audio) {
		if (MsgHistoryPlayableWrapper.class.isInstance(audio)) {
			return playableMessageHistory.isTheSame(((MsgHistoryPlayableWrapper) audio).getPlayableMessageHistory());
		} else if (PlayableFile.class.isInstance(audio)) {
			PlayableFile playableFile = (PlayableFile) audio;
			IMMessage attachMessage = playableFile.getAttachMessage();
			if (attachMessage != null) {
				return playableMessageHistory.isTheSame(attachMessage);
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
}
